package sk.octopuss.archery.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.URL;

import sk.octopuss.archery.annotation.RegexPattern;


@Entity
@Table(name="Item")
public class Item {
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	public void setId(final Long id) {
		this.id = id;
	}
	@Column( name = "name", nullable = false, length=50)
	public String getName() {
		return name;
	}
	public void setName(final String name) {
		this.name = name;
	}
	@ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="brand_id")
	public Brand getBrand() {
		return brand;
	}
	public void setBrand(final Brand brand) {
		this.brand = brand;
	}
	@ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="category_id")
	public Category getCategory() {
		return category;
	}
	public void setCategory(final Category category) {
		this.category = category;
	}
	@Column( name = "catalogueNumber", nullable = false, length=10)
	public String getCatalogueNumber() {
		return catalogueNumber;
	}
	public void setCatalogueNumber(final String catalogueNumber) {
		this.catalogueNumber = catalogueNumber;
	}
	@Column( name = "imageUrl")
	public String getImageUrl() {
		return imageUrl;
	}
	public void setImageUrl(final String imageUrl) {
		this.imageUrl = imageUrl;
	}
	public String getSpecification() {
		return specification;
	}
	public void setSpecification(final String specification) {
		this.specification = specification;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(final String description) {
		this.description = description;
	}
	/**
	 * @return the thumbNail
	 */
	public String getThumbnail() {
		return thumbnail;
	}
	/**
	 * @param thumbNail the thumbNail to set
	 */
	public void setThumbnail(final String thumbNail) {
		this.thumbnail = thumbnail;
	}
	@Override 
	public String toString(){
		return "catalogueNumber:" + catalogueNumber;
	}
	private Long id;
	@NotEmpty
	private String name;
	@NotNull
	private Brand brand;
	@NotNull
	private Category category;
	
	@RegexPattern(source="domain.Item.catalogueNumber.pattern")
	@Column(updatable=false)
	private String catalogueNumber;
	
	public Item() {}
	
	public Item(final Long id, final String name, final Brand brand, final Category category, final String catalogueNumber, final String imageUrl,
			final String description, final String specification) {
		super();
		this.id = id;
		this.name = name;
		this.brand = brand;
		this.category = category;
		this.catalogueNumber = catalogueNumber;
		this.imageUrl = imageUrl;
		this.description = description;
		this.specification = specification;
	}
	
	@URL
	@NotNull
	private String imageUrl;
	
	private String thumbnail;
	private String description;
	private String specification;
}
